<%= content_for :title, t("scaffold.edit.title", model: "Add On") %>
<%= add_on_layout(@add_on) do %>
  <div class="space-y-4">
    <div>
      <h2 class="text-lg font-bold">Endpoints</h2>
      <%= render "add_ons/endpoints/index", add_on: @add_on, endpoints: @endpoints, ingresses: @ingresses %>
      <% if @endpoints.empty? %>
        <p class="text-gray-500">No endpoints found</p>
      <% end %>
    </div>
    <div>
      <div class="flex items-center justify-between mb-2">
        <h2 class="text-lg font-bold">Configuration</h2>
        <% if @add_on.installed? %>
          <%= link_to "Download Values", download_values_add_on_path(@add_on), class: "btn btn-outline btn-sm", target: "_blank" %>
        <% end %>
      </div>
      <%= form_with(model: @add_on) do |form| %>
        <div class="form-group" data-controller="yaml-editor">
          <%= form.label :values_yaml, "Values YAML" %>
          <%= form.text_area(
            :values_yaml,
            class: "code textarea textarea-bordered w-full",
            rows: 5,
            value: @service.values_yaml.to_yaml,
            data: { 'yaml-editor-target': 'textarea' }
          ) %>
          <div data-yaml-editor-target="editor" class="mt-2"></div>
        </div>
        <div class="form-footer">
          <%= form.submit "Save", class: "btn btn-primary" %>
        </div>
      <% end %>
      <div class="text-sm text-gray-500">
        Changes to the values.yaml will be applied to the chart immediately.
      </div>
    </div>

    <div>
      <h2 class="text-2xl font-bold">Danger zone</h2>
      <hr class="mt-3 mb-4 border-t border-base-300" />
      <div class="mt-6">
        <%= button_to @add_on, method: :delete, class: "btn btn-error btn-outline group mt-2", form: { data: { turbo_confirm: t("are_you_sure") } } do %>
          <iconify-icon icon="lucide:trash" height="20" class="text-error group-hover:text-error-content"></iconify-icon>
          Delete Add-on
        <% end %>
        <div class="mt-2 text-sm text-gray-500">
          This will uninstall the add-on from the cluster (equivalent to `helm uninstall`)
        </div>
      </div>
    </div>
  </div>
<% end %>